<?php
require('config.php');

        $text=$_REQUEST['text'];
        $pai=$_REQUEST['pai'];
        $cat=$_REQUEST['cat'];
        $pinpai=$_REQUEST['pinpai'];
        $money_stat=$_REQUEST['money_stat'];
        $money_end=$_REQUEST['money_end'];
		// $text='1';
  //       $pai='all';
  //       $cat='0';
  //       $pinpai='0';
  //       $money_stat='0';
  //       $money_end='0';

        $time=time();
		$sql="select * from `".$oto."_goods` as a,`".$oto."_goods_group` as b where a.isGroup='1' and a.goodsId=b.goodsId and a.shopId=b.shopId and b.goodsGroupStatus='1' and b.startTime<='{$time}' and b.endTime>='{$time}' and a.goodsFlag='1' and a.isSale='1' ";
		if(isset($cat))
		{
			if($cat==0 || $cat=='0') ;
			else  $sql.=" and ".$oto."_goods.goodsCatId2='{$cat}'";
		}
		if($pai=='shaixuan')
		{
			if($pinpai!=0) $sql.=" and brandId='$pinpai'";
			if($money_end!=0) $sql.=" and groupPrice<='$money_end' and groupPrice>='$money_stat' ";
		}
		if($pai=='all')
		{
			$sql.=" order by endTime ASC";
		}
		if($pai=='xiaoliang')
		{
			$sql.='order by `saleCount` DESC';
		}
		if($pai=='remen')
		{
			$sql.='order by `isHot` DESC';
		}
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$goods_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
				$time_star=time();
				$time_end=$time_star-3600*24*30;
				$time_star1=date('Y-m-d H:i:s',$time_end);
				$time_end1=date('Y-m-d H:i:s',$time_star);
		if(isset($goods_info))
		{
			for($i=0;$i<count($goods_info);$i++)
			{
				$goods_id=$goods_info[$i]['goodsId'];
				
				$sql="select * from `".$oto."_orders` as o,`".$oto."_order_goods` as g where o.orderId=g.orderId and g.goodsId='{$goods_id}' and o.createTime>='$time_star1' and o.createTime<='$time_end1' and orderStatus='4'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$order_list[$i][]=$row;//将取得的所有数据赋值给person_info数组
				}
				$sum=0;
				if(isset($order_list[$i]))
				{
					for($j=0;$j<count($order_list[$i]);$j++)
					{
						$sum+=$order_list[$i][$j]['goodsNums'];
					}
				}
				$goods_info[$i]['yue_xiaoliang']=$sum;
			}
			
		}
		echo json_encode($goods_info);
?>